<template>
	<view class="dangan">
		<view class="da_box" v-if="list.length">
			
			
			<uni-card 
			    :title="item.name" 
			    mode="title" 
				v-for="item in list"
				:key="item._id"
			    :is-shadow="true" 
			    thumbnail="https://mini-one-1258127031.cos.ap-chengdu.myqcloud.com/icon/%E6%96%87%E4%BB%B6.png" 
			    :extra="item.relationship" 
			    note="我的档案"
			>
			    <view class="da_content">
			    	
					<button type="primary" @click="ShowDangan(item._id)">查看完整档案</button>
					<button type="warn"  @click="deleteDan(item._id)">删除档案</button>
			    </view>
			</uni-card>
		</view>
		
		<view class="addda" v-else>
			<view class="icons">
				<text class="iconfont icondangan-"></text>
			</view>
			<text>暂无病例档案,请添加</text>
		</view>
		<view class="btnbox">
			<button type="primary" @click="addDangan">添加档案</button>
			
		</view>
	</view>
</template>

<script>
	import uniCard from '@/components/uni-card/uni-card.vue'
	export default {
		computed: {
			token() {
				return this.$store.state.token;
			}
		},
	
		    components: {uniCard},
		
		data() {
			return {
				list: [],
				count: 0,
			}
		},
		filters: {
			getGender( val ) {
				if(val == 1) {
					return "男"
				} else if (val == 2) {
					return "女"
				} else {
					return "用户保密"
				}
			},
		},
		onShow() {
			 this.getUserDangan()
		},
	    methods: {
			// 获取用户的档案
			async getUserDangan() {
				let res = await this.$Request("/admin/getUserDangan","", this.token)
				console.log(res);
				let code = res.data.code 
				if(code == 200) {
					this.list = res.data.data.mydangan
					
				}
			},
			// 添加档案
			addDangan() {
				uni.navigateTo({
					url: "../dananadd/danganadd?type=add"
				})
			},
			// 查看完整档案
			ShowDangan( id ) {
				console.log(id);
				uni.navigateTo({
					url: `/pages/danganinfo/danganinfo?id=${id}`
				})
			},
			// 隐藏档案
			async deleteDan( id ) {
				// console.log(id);
				let self = this
				uni.showModal({
					title:"提示",
					content:"确定删除档案?",
					showCancel:true,
					cancelText:"否",
					confirmText:"是",
					confirmColor:"green",
					cancelColor:"red",
					async success(res) {
						if(!res.cancel) {
							let res = await self.$Request("/admin/changeDanganStatus", { id }, self.token)
							let code = res.data.code 
							if(code == 204) {
								uni.showToast({
									title: "删除成功",
									icon:"success"
								})
								self.getUserDangan()
							}
						}
					},
				})
				
			},
		},
	}
</script>

<style scoped lang="scss">
	.dangan {
		width: 100%;
		box-sizing: border-box;
		padding: 10rpx 20rpx;
		position: relative;
		left: 0;
		top: 0;
		.addda {
			width: 100%;
			box-sizing: border-box;
			padding: 20% 0;
			color: #999999;
			font-size: 30rpx;
			text-align: center;
			.icons {
				text {
					font-size: 200rpx;
				}
			}
		}
		.btnbox {
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;
			position: fixed;
			left: 0;
			bottom: 40rpx;
			button {
				font-size: 26rpx;
				border-radius: 60rpx;
			}
		}
		.da_content{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			button {
				font-size: 26rpx;
				width: 250rpx;
				border-radius: 60rpx;
				margin: 0 10rpx;
			}
			
		}
	}
</style>
